import 'package:dio/dio.dart';
import 'package:flutter_van_android/api/endpoints.dart';

import '../utils/dio_interceptors.dart';

class ApiClient {
  static final Dio _dio = Dio(BaseOptions(
    baseUrl: Endpoints.baseUrl, // 设置基础 URL
    connectTimeout: const Duration(seconds: 10), // 连接超时
    receiveTimeout: const Duration(seconds: 10), // 接收超时
    headers: {
      'Content-Type': 'application/json', // 默认头部
    },
  ));

  // 获取 Dio 实例
  static Dio get instance {
    _dio.interceptors.add(LogInterceptor(
      request: true,
      responseBody: true,
      requestHeader: true,
    )); // 添加日志拦截器
    _dio.interceptors.add(DioInterceptors());
    return _dio;
  }
}
